<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'IoT',
    'name' => 'IoT',
    'version' => '1.0.0',
    'basePath' => dirname(__DIR__),
    'language' => 'zh-CN',
    'timeZone' => 'Asia/Shanghai',
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'IoT_dev_IoT_dev_IoT_dev_IoT_dev_',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
            'keyPrefix' => 'IoT_',
        ],
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
            'loginUrl' => ['/user/login'],
            'identityCookie' => ['name' => '_user_identity', 'httpOnly' => true],
            'idParam' => '_uid',
            'returnUrlParam' => '__user_returnUrl',
        ],
        'agent' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\models\Agent',
            'enableAutoLogin' => true,
            'loginUrl' => ['/agent/login'],
            'identityCookie' => ['name' => '_agent_identity', 'httpOnly' => true],
            'idParam' => '_aid',
            'returnUrlParam' => '__agent_returnUrl',
        ],
        'storage' => [
            'class' => 'yii\web\Storage',
            'identityClass' => 'app\models\Storage',
            'enableAutoLogin' => true,
            'loginUrl' => ['/storage/storage_list'],
            'identityCookie' => ['name' => '_storage_identity', 'httpOnly' => true],
            'idParam' => '_id',
            'returnUrlParam' => '__storage_returnUrl',
        ],
        'manager' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\models\Manager',
            'enableAutoLogin' => true,
            'loginUrl' => ['/admin/login'],
            'identityCookie' => ['name' => '_manager_identity', 'httpOnly' => true],
            'idParam' => '_mid',
            'returnUrlParam' => '__manager_returnUrl',
        ],
        'errorHandler' => [
            'class' => 'app\models\ErrorHandler',
            'errorAction' => 'site/error',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'maxLogFiles' => 99,
                    'levels' => ['error', 'warning'],
                    'logVars' => [
                        '_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER',
                        '!_SERVER.CONTENT_TYPE',
                        '!_SERVER.DOCUMENT_ROOT',
                        '!_SERVER.DOCUMENT_URI',
                        '!_SERVER.FCGI_ROLE',
                        '!_SERVER.GATEWAY_INTERFACE',
                        '!_SERVER.HOME',
                        '!_SERVER.HTTP_ACCEPT',
                        '!_SERVER.HTTP_ACCEPT_ENCODING',
                        '!_SERVER.HTTP_CONNECTION',
                        '!_SERVER.HTTP_CONTENT_LENGTH',
                        '!_SERVER.HTTP_CONTENT_TYPE',
                        '!_SERVER.HTTP_HOST',
                        '!_SERVER.PATH_INFO',
                        '!_SERVER.PHP_SELF',
                        '!_SERVER.QUERY_STRING',
                        '!_SERVER.REDIRECT_STATUS',
                        '!_SERVER.REQUEST_SCHEME',
                        '!_SERVER.SCRIPT_FILENAME',
                        '!_SERVER.SCRIPT_NAME',
                        '!_SERVER.SERVER_ADDR',
                        '!_SERVER.SERVER_NAME',
                        '!_SERVER.SERVER_PORT',
                        '!_SERVER.SERVER_PROTOCOL',
                        '!_SERVER.SERVER_SOFTWARE',
                        '!_SERVER.USER',
                    ],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        'authManager' => [
            'class' => 'app\models\RbacManager',
            'itemTable' => '{{%auth_item}}',
            'assignmentTable' => '{{%auth_assignment}}',
            'itemChildTable' => '{{%auth_item_child}}',
        ],
        'view' => [
            'theme' => [
                'basePath' => '@app/themes/basic',
                'baseUrl' => '@web',
                'pathMap' => [
                    '@app/views' => '@app/themes/basic',
                    '@app/modules' => '@app/themes/basic/modules',
                    '@app/widgets' => '@app/themes/basic/widgets',
                ],
            ],
        ],
        'formatter' => [
            'nullDisplay' => '',
            'dateFormat' => 'php:Y-m-d',
            'datetimeFormat' => 'php:Y-m-d H:i:s',
            'sizeFormatBase' => 1024,
        ],
        'assetManager' => [
            'linkAssets' => true,
            'bundles' => [
                'yii\web\JqueryAsset' => [
                    'js' => [
                        'jquery.min.js',
                    ]
                ],
            ],
        ],
    ],
    'modules' => [
        'api' => [
            'class' => 'app\modules\api\Module',
        ],
        'admin' => [
            'class' => 'app\modules\admin\Module',
        ],
        'user' => [
            'class' => 'app\modules\user\Module',
        ],
        'agent' => [
            'class' => 'app\modules\agent\Module',
        ],
        'storage' => [
            'class' => 'app\modules\storage\Module',
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
